#pragma once
#include "event/cabinet.hpp"
#include "event/event.hpp"

#include <chrono>
#include <functional>

namespace ibox::event {
using namespace ibox::cabinet;

class EpollLoop;

class TimerEvent : public Event {
    using CallbackFunc = std::function<void()>;

public:
    TimerEvent(EpollLoop *loop, std::chrono::milliseconds interval, Mode mode)
        : m_loop{loop}, m_interval{interval}, m_mode{mode} {}

    ~TimerEvent() = default;

    void set_callback(CallbackFunc cb) { m_cb = std::move(cb); };
    bool is_enabled() const { return m_is_enabled; };
    bool enable();
    bool disable();

    EpollLoop *get_loop() const { return m_loop; }
    void on_event();

private:
    EpollLoop *m_loop{};
    Token *m_token{};
    bool m_is_enabled = false;
    std::chrono::milliseconds m_interval{};
    Mode m_mode = Mode::Oneshot;
    CallbackFunc m_cb{};
};

} // namespace ibox::event
